<div id="memos">
	<h2><?php __('Memos');?></h2>
	<table cellpadding="0" cellspacing="0">

	<?php
	$i = 0;
	foreach ($memos as $memo):
            $class = null;
            $wasSent = false;
            $hasUrl = false;
            $archived = false;
            if ($memo['AccountAsSender']['id'] != null){
                $wasSent = true;
            }
            if ($memo['Memo']['archived'] == 1){
                $archived = true;
            }
            if ($memo['Memo']['url'] != null){
                $hasUrl = true;
            }
            if ($archived || $wasSent){
                $class = ' class="'.($wasSent?'memoSent ':'').($archived?'archived ':'').'"';
            }

	?>
	<tr<?php echo $class;?>>
		<td>
                    <?php 
                    if ($wasSent)
                        echo $this->Html->link($memo['AccountAsSender']['name'], array('controller' => 'accounts', 'action' => 'view', $memo['AccountAsSender']['id'])).": ";
                    if ($hasUrl)
                        echo $this->Html->link($memo['Memo']['text'], $memo['Memo']['url']);
                    else
                        echo $memo['Memo']['text'];
                    ?>
                </td>
		<td>
			
		</td>
		<td><?php echo $memo['Memo']['priority']; ?>&nbsp;</td>
		<td class="actions">
                    <?php if (!$archived): ?>
			<?php echo $this->Html->link(__('Move to archive', true), array('action' => 'toArchive', $memo['Memo']['id'])); ?>
			<?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $memo['Memo']['id'])); ?>
			<?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $memo['Memo']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $memo['Memo']['id'])); ?>
                    <?php else: ?>
                        <?php echo $this->Html->link(__('Back to top', true), array('action' => 'fromArchive', $memo['Memo']['id'])); ?>
			<?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $memo['Memo']['id'])); ?>
			<?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $memo['Memo']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $memo['Memo']['id'])); ?>
                    <?php endif ?>
		</td>
	</tr>
<?php endforeach; ?>
	</table>

        <div id="memos-add">
            loading...
        </div>
</div>
<script>
new Request.HTML({update:'memos-add', url:'memos/add'}).post();
</script>